CROSS_COMPILE =
# CROSS_COMPILE = arm-linux-gnueabihf-
AS		= $(CROSS_COMPILE)as
LD		= $(CROSS_COMPILE)ld
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CC) -E
AR		= $(CROSS_COMPILE)ar
NM		= $(CROSS_COMPILE)nm

STRIP		= $(CROSS_COMPILE)strip
OBJCOPY		= $(CROSS_COMPILE)objcopy
OBJDUMP		= $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM
export STRIP OBJCOPY OBJDUMP

CFLAGS := -Wall -O2 -g 
CFLAGS += -I $(shell pwd)/driver/elog/inc/
CFLAGS += -I $(shell pwd)/driver/cJSON/ 
CFLAGS += -I $(shell pwd)/driver/tool/ 
CFLAGS += -I $(shell pwd)/driver/libuuid/
CFLAGS += -I $(shell pwd)/driver/sqlite/
CFLAGS += -I $(shell pwd)/driver/libmodbus/

LDFLAGS := -pthread -ldl

export CFLAGS LDFLAGS

TOPDIR := $(shell pwd)
export TOPDIR

TARGET := main


obj-y += main.o
obj-y += driver/


all : start_recursive_build $(TARGET)
	mv $(TARGET)  build

start_recursive_build:
	make -C ./ -f $(TOPDIR)/Makefile.build

$(TARGET) : built-in.o
	$(CC) -o $(TARGET) built-in.o $(LDFLAGS) 

clean:
	rm -f $(shell find -name "*.o")
	rm -f $(TARGET)

distclean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(TARGET)
	
